package moxl.parser.assemblers.cdata;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;
import moxl.tokenizer.xml.cdata.ContentCharacterDataStartState;

public class CharacterDataAssembler extends AbstractTokenFedMarkupAssembler<CharacterDataAssemblerState, CharacterDataAssemblerContext>
{
	@Override
	protected CharacterDataAssemblerContext createAssemblerContext(TokenStream tstream) throws TokenizerException
	{
		CharacterDataAssemblerContext ctx = new CharacterDataAssemblerContext(tstream);
		ctx.setTokenStreamMode(ContentCharacterDataStartState.getInstance());
		return ctx;
	}

	@Override
	protected void handleInput(XmlTokenType type, CharacterDataAssemblerContext ctx) throws ParserException, TokenizerException
	{
		CharacterDataStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case CHARACTER_DATA:
			delegate.acceptCharacterData(ctx);
			break;

		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
	}
}
